The present invention relates generally to using registers in various situations such as program modification or code instrumentation. More specifically, the invention relates to preserving the content of a first register so that this register may be used without affecting the content of a second register.
Program modification is often implemented in code instrumentation, which is a process for analyzing programming code, usually executables. During this process, new instructions (or probe code) are added to the program, and, consequently, the original code in the program is changed and/or relocated, resulting in modified or instrumented code. Some examples of added instructions include adding values to a register, moving the content of one register to another register, moving the address of some data to some registers, etc. Code instrumentation may be done both statically and dynamically (i.e., while the program is running). In one approach, probe code is binary or assembly code.
Registers refer to special, high-speed areas storing data to be processed by the program code. A free register is a register that can be used in code instrumentation without violating program correctness. Compiler annotations and data flow analysis may provide information to identify free registers. However, compiler annotations require specific support from the compiler while data flow analysis is expensive. Alternatively, modifying the output parameters of a program statement provides a method for allocating registers. However, in one embodiment, this approach cannot be used to obtain free registers if the original code already uses all registers that can be made available using this approach. In an alternative approach, before the registers are used in the probe code, the content of the registers is saved to memory, and, after the registers are used in the probe code, the content of the registers is restored from memory. Unfortunately, in various situations, saving the content of a register to memory may cause the system to change the content of other registers, which changes the program semantics. For example, in the IA64 system architecture of Hewlett-Packard Company of Palo Alto, Calif., saving/restoring the content of a general register on the memory stack, while also preserving the NaT bit associated with the general register, causes the system to save the NaT bit into the UNaT register. This changes the content of the UNaT register as seen by the original program code, which may result in changed program behavior.
Based on the foregoing, it is clearly desirable that mechanisms be provided to solve the above deficiencies and associated problems.
The present invention, in various embodiments, provides techniques for preserving first content in a first register while maintaining second content in a second register wherein saving the first content to a particular location changes the second content in the second register. In one embodiment, the first register is a general register, the second register is a UNaT register, and each general register is associated with a NaT bit. In one aspect, saving the content of a general register to memory causes the system to save the associated NaT bit to the UNaT register, which, in effect, changes the content of the UNaT register. To preserve the content of the UNaT register while saving the content of a general register so that the general register may be used in programming code modification, the content of the general register, in one embodiment, is saved to a floating-point register. After the general register has been used, the content of the general register saved in the floating-point register is restored to the general register.
In one embodiment, when the content of a general register is saved to the floating-point register, the NaT bit associated with the general register is also saved. Further, if the NaT bit is not xe2x80x9cset,xe2x80x9d then the content of the general register needs to be restored, and, if the NaT bit is set, then the content of the general register may be discarded. Consequently, if the NaT bit is set, then only the NaT bit is restored. Conversely, if the NaT bit is not set, then both the content of the general register and the NaT bit are restored. Where it is desirable that the content of the floating-point register be preserved, this content is saved to memory and restored to the floating-register after the floating-point register has been used.